package com.example.home.attorney.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.attorney.bean.AttorneySearchBean;
import com.example.home.attorney.bean.SearchResult;
import com.example.home.tool.OKHttpTool;
import com.google.gson.Gson;

import static com.example.home.tool.StaticActi.ip;

public class AttorneyDetail extends AppCompatActivity {

    private String name;
    private ImageView imgUrl;
    private TextView Attname;
    private TextView workStartAt;
    private TextView serviceTimes;
    private TextView legalExpertiseName;
    private TextView favorableRate;
    private Button consult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attorney_detail);
        Intent intent = getIntent();
        String attorney1 = intent.getStringExtra("attorney");
        Gson gson = new Gson();
        AttorneySearchBean.RowsBean attorney = gson.fromJson(attorney1, AttorneySearchBean.RowsBean.class);
        name = attorney.getName();

        initView();
        getSearchData();
    }



    private void getSearchData() {
        OKHttpTool.doNetRequest("prod-api/api/lawyer-consultation/lawyer/list?name="+name,
                OKHttpTool.GET,
                SearchResult.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        SearchResult rcvListBean = (SearchResult) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                               if (rcvListBean.getTotal() == 0){
                                   Toast.makeText(AttorneyDetail.this,"暂无该律师",Toast.LENGTH_SHORT).show();
                               }else {
                                   Glide.with(AttorneyDetail.this).load(ip+rcvListBean.getRows().get(0).getAvatarUrl()).into(imgUrl);
                                   Attname.setText(rcvListBean.getRows().get(0).getName());
                                   workStartAt.setText("从业年限:"+rcvListBean.getRows().get(0).getWorkStartAt());
                                   serviceTimes.setText("咨询人数:"+rcvListBean.getRows().get(0).getServiceTimes());
                                   legalExpertiseName.setText("擅长:"+rcvListBean.getRows().get(0).getLegalExpertiseName());
                                   favorableRate.setText("好评率:"+rcvListBean.getRows().get(0).getFavorableRate());
                                   consult.setOnClickListener(new View.OnClickListener() {
                                       @Override
                                       public void onClick(View v) {
                                           Toast.makeText(AttorneyDetail.this,"暂未完成",Toast.LENGTH_SHORT).show();
                                       }
                                   });
                               }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initView() {

        imgUrl = findViewById(R.id.imgUrl);
        Attname = findViewById(R.id.name);
        workStartAt = findViewById(R.id.workStartAt);
        serviceTimes = findViewById(R.id.serviceTimes);
        legalExpertiseName = findViewById(R.id.legalExpertiseName);
        favorableRate = findViewById(R.id.favorableRate);
        consult = findViewById(R.id.consult);

    }

}